<!-- 收货地址 -->
<template>
	<view class="box">
		<u-navbar :isFixed="true" title="收货地址" :borderBottom="false"></u-navbar>
		<view class="item" v-for="(item,index) in list" :key="index">
			<view class="content">
				<view class="msg flex_bet_align">
					<text>{{item.username}}</text>
					<text>{{item.mobile}}</text>
				</view>
				<view class="flex_align adbox">
					<!-- <view class="tag" v-if="item.is_default==1">默认</view> -->
					<view class="address">{{item.province}}{{item.city}}{{item.area}} {{item.address}}</view>
				</view>
			</view>
			<!-- <view class="opt" v-if="place_order>0" @click="selectSite(index)">使用地址</view> -->
			<view class="operate flex_bet_align">
				<view class="">
					<view class="opt" v-if="place_order>0" @click="selectSite(index)">使用地址</view>
					<u-radio-group v-model="radiovalue" @change="groupChange" v-else>
						<u-radio :name="item.is_default" @change="setmo(item)" active-color="#35BF8D">
							{{item.is_default==1?"默认地址":"设为默认"}}
						</u-radio>
					</u-radio-group>
				</view>
				<view class="flex_bet_align">
					<view class="delete iconfont icon-cangpeitubiao_shanchu" @click="deleteress(item.id)"></view>
					<navigator hover-class="none" :url="'newAddress?id='+item.id" class="iconfont icon-bianji1">
					</navigator>
				</view>
			</view>
		</view>
		<view class="not_more" v-if="list.length<1">
			<image src="../static/img/wdizhi.png" mode="widthFix"></image>
			<view class="text">暂无地址</view>
		</view>
		<view style="height:135rpx;"></view>
		<navigator hover-class="none" url="newAddress" class="btn">添加收货地址</navigator>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				list: [],
				addressid: 0,
				names: "123",
				place_order: 0, //0个人中心进入， 1选择收货地址进入
				radiovalue: ''
			}
		},
		onLoad(options) {
			_this = this
			if (options.place_order) {
				_this.place_order = options.place_order
			}
			_this.addressid = options.addressid ? options.addressid : 0
			_this.getdata()
		},
		methods: {
			// 刷新当前页面的指定方法
			isonshow() {
				_this.getdata()
			},
			// 获取数据
			getdata() {
				_this.$api.get("getaddress", {}).then(data => {
					_this.list = data
					for (let i of data) {
						if (i.is_default == 1) {
							_this.radiovalue = i.is_default
						}
					}
				});
			},
			//删除地址
			deleteress(id) {
				uni.showModal({
					title: '提示',
					content: '确认删除？',
					success: function(res) {
						if (res.confirm) {
							_this.$api.get("deladdress", {
								detail_id: id
							}).then(data => {
								wx.showToast({
									title: '修改成功'
								})
								_this.getdata()
							});
						}
					}
				});
			},
			selectSite(index) {
				uni.setStorageSync("selectshouhuo", _this.list[index])
				wx.navigateBack({
					delta: 1
				})
			},
			groupChange(e) {
				_this.radiovalue = e
			},

			setmo(e) {
				_this.$api.post("addaddress", {
					mobile: e.mobile,
					address: e.address,
					username: e.username,
					province: e.province,
					city: e.city,
					area: e.area,
					is_default: 1,
					opt_type: 2,
					id: e.id
				}).then(data => {
					wx.showToast({
						title: '设置成功',
						duration: 1500
					})
					setTimeout(function() {
						_this.getdata()
					}, 1000);
				});


			}

		}
	}
</script>

<style lang="scss" scoped>
	.box {
		background-color: #F3F3F3;
		min-height: 100vh;
	}

	.item {
		padding: 30rpx 30rpx 0;

		.adbox {
			height: 98rpx;
			font-size: 26rpx;
			color: #666666;
		}

		.msg {
			font-size: 28rpx;
			font-weight: 700;
			color: #333333;
			margin-bottom: 25rpx;
		}

		.tag {
			width: 70rpx;
			height: 36rpx;
			background: #38be8c;
			border-radius: 18rpx;
			line-height: 36rpx;
			font-size: 18rpx;
			text-align: center;
			color: #ffffff;
			margin-right: 10rpx;
		}

	}

	.opt {
		padding: 0 20rpx;
		margin-left: 20rpx;
		line-height: 60rpx;
		border-radius: 46rpx;
		text-align: center;
		color: #FFFFFF;
		font-size: 30rpx;
		background: linear-gradient(86deg, #37bd8d 3%, #06adb9 97%);
	}

	.content {
		padding: 40rpx 54rpx 0rpx;
		border-bottom: 2rpx solid #eee;
		flex: 1;
		background: #fff;
	}

	.operate {
		height: 87rpx;
		line-height: 86rpx;
		padding: 0rpx 54rpx;
		background: #fff;

		.iconfont {
			width: 100%;
			text-align: center;
			margin-left: 47rpx;
		}
	}

	.btn {
		width: 690rpx;
		height: 90rpx;
		background: linear-gradient(86deg, #37bd8d 3%, #06adb9 97%);
		border-radius: 46rpx;
		font-size: 32rpx;
		font-weight: 700;
		text-align: center;
		line-height: 90rpx;
		color: #ffffff;
		position: fixed;
		bottom: 44rpx;
		left: 30rpx;
	}
</style>
